package edu.nf.hotel.ordersdao.impl;

import edu.nf.hotel.orders.OrderInfo;
import edu.nf.hotel.ordersdao.OrderInfoDao;
import edu.nf.hotel.util.ConnUtils;
import org.apache.ibatis.jdbc.SQL;
import org.nf.db.util.SqlExecutor;
import org.nf.db.util.result.BeanListHandler;

import java.util.List;

/**
 * @Date 2023-06-29
 * @Author 带土
 */
public class OrderInfoDaoImpl implements OrderInfoDao {
    @Override
    public void getAddOrderInfo(OrderInfo o) {
        SqlExecutor executor = new SqlExecutor(ConnUtils.getConnection());
        String sql ="insert into order_info (ro_id,disc) values (?,?)";
        executor.executeUpdate(sql,o.getRoId(),o.getDisc());
    }

    @Override
    public void getDeleteOrderInfo(int orderId) {
        SqlExecutor executor = new SqlExecutor(ConnUtils.getConnection());
        String sql ="delete from order_info where order_id =?";
        executor.executeUpdate(sql,orderId);

    }

    @Override
    public void getUpdateOrderInfo(OrderInfo o) {
        SqlExecutor executor = new SqlExecutor(ConnUtils.getConnection());
        String sql ="update order_info set ro_id=?,disc=?,create_time=? where order_id=?";
        executor.executeUpdate(sql,o.getRoId(),o.getDisc(),o.getCreateTime(),o.getOrderId());
    }

    @Override
    public List<OrderInfo> getAllOrderInfo() {
        SqlExecutor executor = new SqlExecutor(ConnUtils.getConnection());
        BeanListHandler<OrderInfo> handler = new BeanListHandler<>(OrderInfo.class);
        String sql ="select order_id,ro_id,disc,create_time from order_info";
        List<OrderInfo> list = executor.executeQuery(sql, handler);
        list.forEach(orderInfo -> System.out.println(orderInfo.getOrderId()));
        return list;
    }
}
